package com.example.testapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.example.testapplication.fragment.FindFragment;
import com.example.testapplication.fragment.MainFragment;
import com.example.testapplication.fragment.MeFragment;

public class Imtao extends AppCompatActivity implements View.OnClickListener{
    protected LinearLayout mMenuMain;
    protected LinearLayout mMenuFind;
    protected LinearLayout mMenuMe;
    protected MainFragment mainFragment = new MainFragment(); // 首页
    protected FindFragment findFragment = new FindFragment();// 发现
    protected MeFragment meFragment = new MeFragment();// 我的

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_imtao);
        initView();

        // 获取管理类
        this.getSupportFragmentManager().beginTransaction()
                .add(R.id.container_content,mainFragment)
                .add(R.id.container_content,findFragment).hide(findFragment)
                .add(R.id.container_content,meFragment).hide(meFragment).commit();
        // 事务添加 默认显示首页 其他页面隐藏
    }
    // 初始化视图
    public void initView(){
        mMenuMain = (LinearLayout) this.findViewById(R.id.menu_main);
        mMenuFind = (LinearLayout) this.findViewById(R.id.menu_find);
        mMenuMe = (LinearLayout) this.findViewById(R.id.menu_me);

        mMenuMain.setOnClickListener(this);
        mMenuFind.setOnClickListener(this);
        mMenuMe.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.menu_main:
                // 获取管理类
                this.getSupportFragmentManager().beginTransaction()
                        .show(mainFragment)
                        .hide(findFragment)
                        .hide(meFragment).commit();
                break;
            case R.id.menu_find:
                // 获取管理类
                this.getSupportFragmentManager().beginTransaction()
                        .show(findFragment)
                        .hide(mainFragment)
                        .hide(meFragment).commit();
                break;
            case R.id.menu_me:
                // 获取管理类
                this.getSupportFragmentManager().beginTransaction()
                        .show(meFragment)
                        .hide(mainFragment)
                        .hide(findFragment).commit();
                break;

        }
    }
}